#include<bits/stdc++.h>
using namespace std;
int n,ans=-1;
int a[200111],c[200111][2],b[200111][2];
bool f[200111];
void dfs(int dep)
{
    if(dep>n)
    {
        for(int i=0;i<=n+1;i++)
        {
            b[i][0]=0,b[i][1]=0;
            c[i][0]=0,c[i][1]=0;
        }
        int sum=0;
        for(int i=1;i<=n;i++)
        {
            if(b[i-1][0]==1) b[i][0]=1;
            if(b[i-1][1]==1) b[i][1]=1;
            c[i][0]=max(c[i][0],c[i-1][0]);
            c[i][1]=max(c[i][1],c[i-1][1]);
            b[i+1][f[i]]=1;
            c[i+1][f[i]]=i;
        }
        for(int i=1;i<=n;i++) // 0 hong 1 lan
        {
            if(b[i][f[i]]==false) sum+=0;
            else
            {
                if(a[i]==a[c[i][f[i]]]) sum+=a[i];
                else sum+=0;
            }
        }
        ans=max(ans,sum);
    }
    else
    {
        f[dep]=0;
        dfs(dep+1);
        f[dep]=1;
        dfs(dep+1);
    }
}
void work()
{
    ans=-1;
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    dfs(1);
    cout<<ans<<"\n";
}
int main()
{
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    int T;
    cin>>T;
    while(T--) work();
    return 0;
}